package Wires.diagram.edit.parts;

import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;

/**
 * @generated
 */
public class WiresEditPartFactory implements EditPartFactory {

	/**
	 * @generated
	 */
	public EditPart createEditPart(EditPart context, Object model) {
		if (model instanceof View) {
			View view = (View) model;
			switch (Wires.diagram.part.WiresVisualIDRegistry.getVisualID(view)) {

			case Wires.diagram.edit.parts.WiresSpecificationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WiresSpecificationEditPart(
						view);

			case Wires.diagram.edit.parts.AtomicModelTransformationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransformationEditPart(
						view);

			case Wires.diagram.edit.parts.AtomicModelTransformationNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransformationNameEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabelEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabelEditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel2EditPart(view);

			case Wires.diagram.edit.parts.IdentityTransformationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.IdentityTransformationEditPart(
						view);

			case Wires.diagram.edit.parts.IdentityTransformationNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.IdentityTransformationNameEditPart(
						view);

			case Wires.diagram.edit.parts.GenericTransformationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.GenericTransformationEditPart(
						view);

			case Wires.diagram.edit.parts.GenericTransformationNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.GenericTransformationNameEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel3EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel3EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel4EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel4EditPart(view);

			case Wires.diagram.edit.parts.CompositeTransformationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationEditPart(
						view);

			case Wires.diagram.edit.parts.CompositeTransformationNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationNameEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel5EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel5EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel6EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel6EditPart(view);

			case Wires.diagram.edit.parts.Model2TextTransformationEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformationEditPart(
						view);

			case Wires.diagram.edit.parts.Model2TextTransformationNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformationNameEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel7EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel7EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel8EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel8EditPart(view);

			case Wires.diagram.edit.parts.QueryEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.QueryEditPart(view);

			case Wires.diagram.edit.parts.QueryNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.QueryNameEditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel9EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel9EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel10EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel10EditPart(
						view);

			case Wires.diagram.edit.parts.BasicDataEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.BasicDataEditPart(view);

			case Wires.diagram.edit.parts.BasicDataNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.BasicDataNameEditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel11EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel11EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel12EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel12EditPart(
						view);

			case Wires.diagram.edit.parts.ModelEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.ModelEditPart(view);

			case Wires.diagram.edit.parts.ModelNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.ModelNameEditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel13EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel13EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel14EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel14EditPart(
						view);

			case Wires.diagram.edit.parts.ModelTypeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.ModelTypeEditPart(view);

			case Wires.diagram.edit.parts.ModelTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.ModelTypeNameEditPart(view);

			case Wires.diagram.edit.parts.DecisionNodeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNodeEditPart(view);

			case Wires.diagram.edit.parts.DecisionNodeExpressionEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNodeExpressionEditPart(
						view);

			case Wires.diagram.edit.parts.LibraryEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryEditPart(view);

			case Wires.diagram.edit.parts.LibraryNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryNameEditPart(view);

			case Wires.diagram.edit.parts.AtomicModelTransfomationTypeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransfomationTypeEditPart(
						view);

			case Wires.diagram.edit.parts.AtomicModelTransfomationTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransfomationTypeNameEditPart(
						view);

			case Wires.diagram.edit.parts.Model2TextTransformationTypeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformationTypeEditPart(
						view);

			case Wires.diagram.edit.parts.Model2TextTransformationTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformationTypeNameEditPart(
						view);

			case Wires.diagram.edit.parts.QueryTypeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.QueryTypeEditPart(view);

			case Wires.diagram.edit.parts.QueryTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.QueryTypeNameEditPart(view);

			case Wires.diagram.edit.parts.CompositeTransformationTypeEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationTypeEditPart(
						view);

			case Wires.diagram.edit.parts.CompositeTransformationTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationTypeNameEditPart(
						view);

			case Wires.diagram.edit.parts.InputActualParameterEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputActualParameterEditPart(
						view);

			case Wires.diagram.edit.parts.InputActualParameterNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputActualParameterNameEditPart(
						view);

			case Wires.diagram.edit.parts.OutputActualParameterEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.OutputActualParameterEditPart(
						view);

			case Wires.diagram.edit.parts.OutputActualParameterNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.OutputActualParameterNameEditPart(
						view);

			case Wires.diagram.edit.parts.TypeParameterEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.TypeParameterEditPart(view);

			case Wires.diagram.edit.parts.InputActualParameter2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputActualParameter2EditPart(
						view);

			case Wires.diagram.edit.parts.InputActualParameterName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputActualParameterName2EditPart(
						view);

			case Wires.diagram.edit.parts.LibraryRefEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryRefEditPart(view);

			case Wires.diagram.edit.parts.LibraryRefNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryRefNameEditPart(view);

			case Wires.diagram.edit.parts.InputFormalParameterEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputFormalParameterEditPart(
						view);

			case Wires.diagram.edit.parts.InputFormalParameterNameTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.InputFormalParameterNameTypeNameEditPart(
						view);

			case Wires.diagram.edit.parts.OutputFormalParameterEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.OutputFormalParameterEditPart(
						view);

			case Wires.diagram.edit.parts.OutputFormalParameterNameTypeNameEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.OutputFormalParameterNameTypeNameEditPart(
						view);

			case Wires.diagram.edit.parts.LibraryRef2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryRef2EditPart(view);

			case Wires.diagram.edit.parts.LibraryRefName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.LibraryRefName2EditPart(
						view);

			case Wires.diagram.edit.parts.Model2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2EditPart(view);

			case Wires.diagram.edit.parts.ModelName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.ModelName2EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel15EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel15EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel16EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel16EditPart(
						view);

			case Wires.diagram.edit.parts.BasicData2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.BasicData2EditPart(view);

			case Wires.diagram.edit.parts.BasicDataName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.BasicDataName2EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel17EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel17EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel18EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel18EditPart(
						view);

			case Wires.diagram.edit.parts.CompositeTransformation2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformation2EditPart(
						view);

			case Wires.diagram.edit.parts.CompositeTransformationName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationName2EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel19EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel19EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel20EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel20EditPart(
						view);

			case Wires.diagram.edit.parts.AtomicModelTransformation2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransformation2EditPart(
						view);

			case Wires.diagram.edit.parts.AtomicModelTransformationName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.AtomicModelTransformationName2EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel21EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel21EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel22EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel22EditPart(
						view);

			case Wires.diagram.edit.parts.GenericTransformation2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.GenericTransformation2EditPart(
						view);

			case Wires.diagram.edit.parts.GenericTransformationName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.GenericTransformationName2EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel23EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel23EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel24EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel24EditPart(
						view);

			case Wires.diagram.edit.parts.IdentityTransformation2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.IdentityTransformation2EditPart(
						view);

			case Wires.diagram.edit.parts.IdentityTransformationName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.IdentityTransformationName2EditPart(
						view);

			case Wires.diagram.edit.parts.Query2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Query2EditPart(view);

			case Wires.diagram.edit.parts.QueryName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.QueryName2EditPart(view);

			case Wires.diagram.edit.parts.WrappingLabel25EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel25EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel26EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel26EditPart(
						view);

			case Wires.diagram.edit.parts.DecisionNode2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNode2EditPart(view);

			case Wires.diagram.edit.parts.DecisionNodeExpression2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNodeExpression2EditPart(
						view);

			case Wires.diagram.edit.parts.Model2TextTransformation2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformation2EditPart(
						view);

			case Wires.diagram.edit.parts.Model2TextTransformationName2EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.Model2TextTransformationName2EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel27EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel27EditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel28EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel28EditPart(
						view);

			case Wires.diagram.edit.parts.CompositeTransformationTypeCompositeTransformationTypeElsEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.CompositeTransformationTypeCompositeTransformationTypeElsEditPart(
						view);

			case Wires.diagram.edit.parts.DataFlowEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DataFlowEditPart(view);

			case Wires.diagram.edit.parts.DecisionNodeTrueBranchEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNodeTrueBranchEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel29EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel29EditPart(
						view);

			case Wires.diagram.edit.parts.DecisionNodeFalseBranchEditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.DecisionNodeFalseBranchEditPart(
						view);

			case Wires.diagram.edit.parts.WrappingLabel30EditPart.VISUAL_ID:
				return new Wires.diagram.edit.parts.WrappingLabel30EditPart(
						view);
			}
		}
		return createUnrecognizedEditPart(context, model);
	}

	/**
	 * @generated
	 */
	private EditPart createUnrecognizedEditPart(EditPart context, Object model) {
		// Handle creation of unrecognized child node EditParts here
		return null;
	}

	/**
	 * @generated
	 */
	public static CellEditorLocator getTextCellEditorLocator(
			ITextAwareEditPart source) {
		if (source.getFigure() instanceof WrappingLabel)
			return new TextCellEditorLocator((WrappingLabel) source.getFigure());
		else {
			return new LabelCellEditorLocator((Label) source.getFigure());
		}
	}

	/**
	 * @generated
	 */
	static private class TextCellEditorLocator implements CellEditorLocator {

		/**
		 * @generated
		 */
		private WrappingLabel wrapLabel;

		/**
		 * @generated
		 */
		public TextCellEditorLocator(WrappingLabel wrapLabel) {
			this.wrapLabel = wrapLabel;
		}

		/**
		 * @generated
		 */
		public WrappingLabel getWrapLabel() {
			return wrapLabel;
		}

		/**
		 * @generated
		 */
		public void relocate(CellEditor celleditor) {
			Text text = (Text) celleditor.getControl();
			Rectangle rect = getWrapLabel().getTextBounds().getCopy();
			getWrapLabel().translateToAbsolute(rect);
			if (getWrapLabel().isTextWrapOn()
					&& getWrapLabel().getText().length() > 0) {
				rect.setSize(new Dimension(text.computeSize(rect.width,
						SWT.DEFAULT)));
			} else {
				int avr = FigureUtilities.getFontMetrics(text.getFont())
						.getAverageCharWidth();
				rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT,
						SWT.DEFAULT)).expand(avr * 2, 0));
			}
			if (!rect.equals(new Rectangle(text.getBounds()))) {
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
			}
		}
	}

	/**
	 * @generated
	 */
	private static class LabelCellEditorLocator implements CellEditorLocator {

		/**
		 * @generated
		 */
		private Label label;

		/**
		 * @generated
		 */
		public LabelCellEditorLocator(Label label) {
			this.label = label;
		}

		/**
		 * @generated
		 */
		public Label getLabel() {
			return label;
		}

		/**
		 * @generated
		 */
		public void relocate(CellEditor celleditor) {
			Text text = (Text) celleditor.getControl();
			Rectangle rect = getLabel().getTextBounds().getCopy();
			getLabel().translateToAbsolute(rect);
			int avr = FigureUtilities.getFontMetrics(text.getFont())
					.getAverageCharWidth();
			rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT,
					SWT.DEFAULT)).expand(avr * 2, 0));
			if (!rect.equals(new Rectangle(text.getBounds()))) {
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
			}
		}
	}
}
